package serverlet;

import Server.ManagerServer;
import Server.StudentServer;
import user.Student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "addStudentServlet",urlPatterns = "/addStudent")
public class addStudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("UTF-8");
            Student student = new Student();
            student.setNum(request.getParameter("num"));
            student.setName(request.getParameter("name"));
            student.setSex(request.getParameter("sex"));
            student.setBirthday(request.getParameter("birthday"));
            student.setEmail(request.getParameter("Email"));
            student.setRemark(request.getParameter("remark"));
            System.out.println(student);
            StudentServer studentServer = new StudentServer();
            int i = studentServer.addstudentServer(student);
            System.out.println("增加"+i+"行");
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("/managerinit");
            requestDispatcher.forward(request,response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
